
#ifndef _ENTITY_FACTORY_H
#define _ENTITY_FACTORY_H

#include <SFML/Graphics.hpp>
#include <map>
#include <list>
#include <vector>
#include <angelscript.h>

#include "factory.h"
#include "entity.h"




//Entity pointer comparison, for pointers
//This is used to 'sort' the entity list
//so entites are grouped according to there type
struct Entity_ptr_cmp
{
	bool operator()( Entity* lhs, Entity* rhs)
	{
		return * lhs < * rhs;
	}
};




//Spawn structure
struct EntityEmmiter
{
	EntityEmmiter()
	{
		name = "Default";
		start_pos.SetZero();
		velocity.SetZero();
		rotation = 0;
	}

	string name;

	b2Vec2 start_pos;
	b2Vec2 velocity;

	float rotation;

};



//All important Entity system Class
class Entity_Factory : public Factory
{
public:

	//Register Class methods with Script interface
	static bool Register_With_ScriptEngine(asIScriptEngine * engine);

	//Spawn an entity by its name at a certain location
	void Spawn(const string&,  b2Vec2&);
	//Spawn an entity by its emmiter at a certain location
	void Spawn( const EntityEmmiter& );

	//Draw all of the Entities
	void Draw(sf::RenderWindow *);

	//Update all entity Logic
	void Update_Logic( float, asIScriptContext * );	

	//Destroy the Factory
	void Destroy();
	
	std::map < std::string,  Entity* > Type;
	
	static std::list < Entity* > entity_list;

private:
	
	bool Load_TypeIntoList( const string& );
	void RemoveEntity(list< Entity *>::iterator &);

	//we have a Type 
	//and entity list
	//all things of the entity list will basicly be an instance
	//of something from the Type list
	sf::Shape circle_target; 

	//std::list < std::list > base_list;
	//std::list < Entity* > tower_list;
	//std::list < Entity* > creep_list;
};


//only use the single instance entityManager, (makes exporting the class to scripts easy)
extern Entity_Factory entityManager;

#endif